﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Entity;
using School.Entities;

namespace School.Organization
{
    public static class Certificate
    {
        private static SchoolEntities db = new SchoolEntities();

        public static IQueryable<ORG_Certificate> All()
        {           
            var query = from x in  db.ORG_Certificate orderby x.Name select x;

            return query;
        }

        public static ORG_Certificate Single(long id)
        {
            var query = from x in db.ORG_Certificate where x.Id == id select x;

            if (query.Count() > 0)
                return query.First();
            else
                return null;
        }

        public static void Add(ORG_Certificate certificate)
        {
            db.AddToORG_Certificate(certificate);
            db.SaveChanges();
        }

        public static void Update(ORG_Certificate certificate)
        {
            var c = Single(certificate.Id);
            c.Name = certificate.Name;
            c.Campus_Id = certificate.Campus_Id;
            c.Description = certificate.Description;
            c.Code = certificate.Code;
            db.SaveChanges();
        }
    }
}
